//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.order;

import java.awt.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;

// Referenced classes of package org.jpgolay.me.order:
//            PopupOrderRowsGUI, PopupOrderStockRowsGUI
public class OrderGUI extends JPanel {

    public OrderGUI() {
        agencyAddress = null;
        referenceViewer = null;
        customerAddress = null;
        taxViewer = null;
        totalPrice = null;
        orderRowsTable = null;
        dueDateJLabel = null;
        popupOrder = null;
        popupOrderStock = null;
        initialize();
    }

    private void initialize() {
        GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
        setLayout(new GridBagLayout());
        setSize(630, 581);
        setBackground(Color.white);
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.gridheight = 2;
        gridBagConstraints1.ipadx = 299;
        gridBagConstraints1.ipady = 96;
        gridBagConstraints1.insets = new Insets(0, 5, 0, 9);
        gridBagConstraints1.anchor = 17;
        gridBagConstraints2.gridx = 0;
        gridBagConstraints2.gridy = 2;
        gridBagConstraints2.ipadx = 299;
        gridBagConstraints2.ipady = 82;
        gridBagConstraints2.insets = new Insets(1, 5, 0, 9);
        gridBagConstraints2.anchor = 17;
        gridBagConstraints3.gridx = 1;
        gridBagConstraints3.gridy = 1;
        gridBagConstraints3.gridheight = 2;
        gridBagConstraints3.ipadx = 299;
        gridBagConstraints3.ipady = 139;
        gridBagConstraints3.insets = new Insets(5, 10, 0, 6);
        gridBagConstraints3.anchor = 13;
        gridBagConstraints4.gridx = 0;
        gridBagConstraints4.gridy = 5;
        gridBagConstraints4.ipadx = 299;
        gridBagConstraints4.ipady = 75;
        gridBagConstraints4.insets = new Insets(6, 5, 5, 8);
        gridBagConstraints4.anchor = 17;
        gridBagConstraints4.weighty = 0.0D;
        gridBagConstraints5.gridx = 1;
        gridBagConstraints5.gridy = 5;
        gridBagConstraints5.ipadx = 214;
        gridBagConstraints5.ipady = 103;
        gridBagConstraints5.insets = new Insets(3, 5, 5, 5);
        gridBagConstraints5.anchor = 13;
        gridBagConstraints5.weighty = 0.0D;
        gridBagConstraints6.gridx = 0;
        gridBagConstraints6.gridy = 4;
        gridBagConstraints6.gridwidth = 2;
        gridBagConstraints6.ipadx = 599;
        gridBagConstraints6.ipady = 150;
        gridBagConstraints6.insets = new Insets(2, 5, 3, 5);
        gridBagConstraints6.fill = 1;
        gridBagConstraints6.weightx = 1.0D;
        gridBagConstraints6.weighty = 1.0D;
        gridBagConstraints7.gridx = 0;
        gridBagConstraints7.gridy = 3;
        gridBagConstraints7.gridwidth = 2;
        gridBagConstraints7.ipadx = 599;
        gridBagConstraints7.ipady = 4;
        gridBagConstraints7.insets = new Insets(1, 5, 1, 5);
        gridBagConstraints7.fill = 2;
        gridBagConstraints8.gridx = 1;
        gridBagConstraints8.gridy = 0;
        gridBagConstraints8.ipadx = 251;
        gridBagConstraints8.ipady = 7;
        gridBagConstraints8.insets = new Insets(9, 9, 4, 7);
        gridBagConstraints8.anchor = 13;
        add(getAgencyAddress(), gridBagConstraints1);
        add(getReferenceViewer(), gridBagConstraints2);
        add(getCustomerAddress(), gridBagConstraints3);
        add(getTaxViewer(), gridBagConstraints4);
        add(getTotalPrice(), gridBagConstraints5);
        add(getOrderRowsTable(), gridBagConstraints6);
        add(getInfoLabel(), gridBagConstraints7);
        add(getDueDateJLabel(), gridBagConstraints8);
    }

    private JLabel getDueDateJLabel() {
        if (dueDateJLabel == null) {
            dueDateJLabel = new JLabel();
            dueDateJLabel.setText("due date");
            dueDateJLabel.setHorizontalAlignment(4);
        }
        return dueDateJLabel;
    }

    private JLabel getInfoLabel() {
        if (infoLabel == null) {
            infoLabel = new JLabel();
            infoLabel.setText("info");
            infoLabel.setHorizontalAlignment(0);
        }
        return infoLabel;
    }

    private AddressViewer getAgencyAddress() {
        if (agencyAddress == null) {
            agencyAddress = new AddressViewer();
            agencyAddress.setBackground(Color.white);
        }
        return agencyAddress;
    }

    private ReferenceViewer getReferenceViewer() {
        if (referenceViewer == null) {
            referenceViewer = new ReferenceViewer();
            referenceViewer.setBackground(Color.white);
            referenceViewer.setListPiece(new String[]{
                        "DEVIS client", "COMMANDE client", "BL client", "FACTURE client", "AVOIR client", "COMMANDE fournisseur", "FACTURE fournisseur"
                    });
            referenceViewer.setSalespersonLabel("Commercial");
        }
        return referenceViewer;
    }

    private AddressViewerById getCustomerAddress() {
        if (customerAddress == null) {
            customerAddress = new AddressViewerById();
            customerAddress.setBackground(Color.white);
            customerAddress.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
            customerAddress.setIdLabel("Code :");
        }
        return customerAddress;
    }

    private TableViewer getTaxViewer() {
        if (taxViewer == null) {
            taxViewer = new TableViewer();
            taxViewer.setBackground(Color.white);
            taxViewer.setAlternateColor(new Color(255, 255, 220));
            taxViewer.setColumnNames(new String[]{
                        "TVA", "Valeur (%)", "Montant"
                    });
        }
        return taxViewer;
    }

    private TotalPrice getTotalPrice() {
        if (totalPrice == null) {
            totalPrice = new TotalPrice();
            totalPrice.setBackground(new Color(255, 255, 220));
            totalPrice.setDueLabel("Reste du");
            totalPrice.setPartPaymentLabel("Pay\351");
            totalPrice.setTaxLabel("TVA");
            totalPrice.setTotalBeforeTaxLabel("Total HT");
            totalPrice.setTotalPaymentLabel("Total TTC");
            totalPrice.setShippingLabel("Frais de port");
        }
        return totalPrice;
    }

    private TableViewerS getOrderRowsTable() {
        if (orderRowsTable == null) {
            orderRowsTable = new TableViewerS();
            orderRowsTable.setBackground(Color.white);
        }
        return orderRowsTable;
    }

    private PopupOrderRowsGUI getPopupOrder() {
        if (popupOrder == null) {
            popupOrder = new PopupOrderRowsGUI();
        }
        return popupOrder;
    }

    private PopupOrderStockRowsGUI getPopupOrderStock() {
        if (popupOrderStock == null) {
            popupOrderStock = new PopupOrderStockRowsGUI();
        }
        return popupOrderStock;
    }

    public PopupOrderRowsGUI getPopupOrderRows() {
        return getPopupOrder();
    }

    public PopupOrderStockRowsGUI getPopupOrderStockRows() {
        return getPopupOrderStock();
    }

    public AddressViewer getAgencyPanel() {
        return getAgencyAddress();
    }

    public void setInfoField(String infoLabel) {
        getInfoLabel().setText(infoLabel);
    }

    public String getInfoField() {
        return getInfoLabel().getText();
    }

    public void setDueDateField(String dueDate) {
        getDueDateJLabel().setText(dueDate);
    }

    public String getDueDateField() {
        return getDueDateJLabel().getText();
    }

    public ReferenceViewer getReferencesPanel() {
        return getReferenceViewer();
    }

    public void setReferencesPanelEnabled(boolean b) {
        getReferenceViewer().setEnabledDateAndPiece(b);
    }

    public AddressViewerById getAddresseePanel() {
        return getCustomerAddress();
    }

    public TableViewer getTaxTable() {
        return getTaxViewer();
    }

    public TotalPrice getTotalPanel() {
        return getTotalPrice();
    }

    public TableViewerS getRowsTable() {
        return getOrderRowsTable();
    }
    private AddressViewer agencyAddress;
    private ReferenceViewer referenceViewer;
    private AddressViewerById customerAddress;
    private TableViewer taxViewer;
    private TotalPrice totalPrice;
    private TableViewerS orderRowsTable;
    private JLabel infoLabel;
    private JLabel dueDateJLabel;
    private PopupOrderRowsGUI popupOrder;
    private PopupOrderStockRowsGUI popupOrderStock;
}
